package com.aiju.cash.ui.main.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aiju.cash.R;
import com.aiju.cash.ui.multiple_shops.widget.MenuLinearLayout;
import com.aiju.utils.StringUtil;

/**
 * 作者：流冥 on 2017/6/15 10:44
 * 说明：
 */

public class BollterSelectTopView extends LinearLayout {
    private TextView name1;
    private TextView name2;
    private LinearLayout textLinearlayout;

    public BollterSelectTopView(Context context) {
        super(context);
        initView(context);
    }

    public BollterSelectTopView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public BollterSelectTopView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    void initView(Context context) {
        RelativeLayout view = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.layout_bollter_select_top_view, null);
        LayoutParams layoutParams = new LayoutParams(MenuLinearLayout.dip2px(context, 110), MenuLinearLayout.dip2px(context, 53));
        view.setLayoutParams(layoutParams);
        view.setClickable(true);
        setGravity(Gravity.CENTER_VERTICAL);
        view.setBackgroundResource(R.drawable.selector_blotter_item);
        name1 = (TextView) view.findViewById(R.id.name1);
        name2 = (TextView) view.findViewById(R.id.name2);
        textLinearlayout = (LinearLayout)view.findViewById(R.id.textLinearlayout);
        addView(view);
    }

    public void setData(String shopName, String employeeName) {
        name1.setText(shopName);
        if (!StringUtil.isBlank(employeeName)) {
            name2.setVisibility(VISIBLE);
            name2.setText(employeeName);
            name1.setGravity(Gravity.CENTER);
            name2.setGravity(Gravity.CENTER);
        } else {
            name2.setVisibility(GONE);
            name2.setText("");
            setNormal();
        }
    }

    private void setMaxLines(int lines) {
        name1.setMaxLines(lines);
    }
    private void  setTextAliginRight(){
        name1.setGravity(Gravity.RIGHT);
    }

    public void setNormal(){
        setMaxLines(2);
        setTextAliginRight();
    }


}
